package com.techstar.ats.codec.live.decoder;

import io.netty.buffer.ByteBuf;
import com.techstar.ats.codec.DateTimeCodec;
import com.techstar.ats.codec.MessageDecoder;
import com.techstar.ats.codec.StringCodec;
import com.techstar.ats.dxp.live.rep.F08TrainRecord;
import com.techstar.ats.type.DirectionType;
import com.techstar.ats.type.RecordType;
import com.techstar.ats.type.TrainType;

public enum F08TrainRecordDecoder implements MessageDecoder<F08TrainRecord> {
	INSTANCE;

	public F08TrainRecord create() {
		return new F08TrainRecord();
	}

	public void decode(ByteBuf buf, F08TrainRecord value) {
		value.line = buf.readUnsignedShort();
		value.train = new StringCodec(9).get(buf);
		value.global = new StringCodec(12).get(buf);
		value.localSub = buf.readInt();
		value.group = new StringCodec(9).get(buf);
		value.dest = new StringCodec(4).get(buf);
		value.trainType = TrainType.valueOf(buf.readUnsignedShort());
		value.dir = DirectionType.valueOf(buf.readUnsignedByte());
		value.station = buf.readUnsignedShort();
		value.side = buf.readUnsignedShort();
		value.trackName = new StringCodec(20).get(buf);
		value.recordType = RecordType.valueOf(buf.readUnsignedShort());
		value.recordTime = DateTimeCodec.INSTANCE.get(buf);
		buf.skipBytes(4);
	}
}
